local qingmei = fk.CreateSkill{
    name = "ym1__qingmei",
}
local U = require "packages/utility/utility"
Fk:loadTranslationTable{
    ["ym1__qingmei"] = "黥梅",
    [":ym1__qingmei"] = "出牌阶段或当你受到伤害后，若你的蓄谋牌数小于3，你可以发现一张♣牌蓄谋并：1.重置连环状态；2.翻至正面；3.本回合手牌上限-1并将手牌调整至上限。",
    ["#ym1__qingmei-choice1"] = "重置连环状态",
    ["#ym1__qingmei-choice2"] = "翻至正面",
    ["#ym1__qingmei-choice3"] = "调整手牌及上限",
    ["@ym1__qingmei-turn"] = "黥梅",
    ["#ym1__qingmei_trigger"] = "黥梅",
    ["#ym1__qingmei"] = "黥梅：发现一张♣牌蓄谋并执行一项",
    ["#ym1__qingmei-card"] = "选择一张牌蓄谋",
    ["#ym1__qingmei-discard"] = "黥梅：将手牌调整至%arg",
}
qingmei:addEffect("active",{
    anim_type = "masochism",
    card_num = 0,
    target_num = 0,
    card_filter = Util.FalseFunc,
    interaction = function (self, player)
        local choices = {}
        if Self.chained then
            table.insert(choices,"#ym1__qingmei-choice1")
        end
        if not Self.faceup then
            table.insert(choices,"#ym1__qingmei-choice2")
        end
        if Self:getMaxCards() > 0 then
            table.insert(choices,"#ym1__qingmei-choice3")
        end
        return UI.ComboBox {choices = choices, all_choices = {"#ym1__qingmei-choice1","#ym1__qingmei-choice2","#ym1__qingmei-choice3"}}
    end,
    can_use = function (self, player)
        return #table.filter(player:getCardIds(Player.Judge), function(id)
            local c = player:getVirualEquip(id)
            if c and string.find(c.name,"premeditate") then return true end
            return false
          end) < 3 and (player.chained or not player.faceup or player:getMaxCards() > 0)
    end,
    on_use = function (self, room, effect)
        local player = effect.from
        local choice = self.interaction.data
        local cards = room:getCardsFromPileByRule(".|.|club", 3, "allPiles")
        local result = room:askToChooseCard(player,{
            target = player,
            flag = { card_data = { { qingmei.name, table.random(cards, 3) } } },
            skill_name = qingmei.name,
            prompt = "#ym1__qingmei-card",
        })
        --room:notifySkillInvoked(player,qingmei.name)
        U.premeditate (player, result, qingmei.name)

        switch(choice,{
            ["#ym1__qingmei-choice1"] = function()
                --player:broadcastSkillInvoke(qingmei.name,1)
                player:setChainState(false)
            end,
            ["#ym1__qingmei-choice2"] = function()
                --player:broadcastSkillInvoke(qingmei.name,2)
                player:turnOver()
            end,
            ["#ym1__qingmei-choice3"] = function()
                --player:broadcastSkillInvoke(qingmei.name,3)
                room:addPlayerMark(player, "@ym1__qingmei-turn", 1)
                local n = player:getMaxCards() - player:getHandcardNum()
                if n > 0 then
                    player:drawCards(n,qingmei.name)
                elseif n < 0 then
                    room:askToDiscard(player,{
                        max_num = -n,
                        min_num = -n,
                        skill_name = qingmei.name,
                        include_equip = false,
                        cancelable = false,
                        prompt = "#ym1__qingmei-discard:::"..player:getMaxCards()
                    })
                end
            end,
        })
    end,
})
qingmei:addEffect(fk.Damaged,{
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill("ym1__qingmei") and target == player and #table.filter(player:getCardIds(Player.Judge), function(id)
            local c = player:getVirualEquip(id)
            if c and string.find(c.name,"premeditate") then return true end
            return false
          end) < 3 and (player.chained or not player.faceup or player:getMaxCards() > 0)
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local result = room:askToUseActiveSkill(player,{
            skill_name = "ym1__qingmei",
            prompt = "#ym1__qingmei",
            cancelable = true
        })
        if result == true then
        end
    end,
})
qingmei:addEffect("maxcards",{
    correct_func = function(self, player)
        return -player:getMark("@ym1__qingmei-turn")
    end,
})
return qingmei